package com.wpen.unit.cron;

import java.util.Date;

import com.wpen.unit.exception.BizException;

/**
 * 
 * @author Wang Peng
 * @date 2022-12-06
 */
public class CronUtil {

    public static Date getTime(String cron, Date fromTime) {
        try {
            Date nextValidTime = new CronExpression(cron).getNextValidTimeAfter(fromTime);
            return nextValidTime;
        } catch (Exception e) {
            throw new BizException("E00901", cron);
        }
    }

    public static Long getTimestamp(String cron, Date fromTime) {
        return getTime(cron, fromTime).getTime();
    }

}
